QuickTime 4 API Documentation

QuickTime 4 Reference

Previous | Chapter Top | Chapter Contents | Next |

PowerPC-Native Component Manager Support

The Component Manager was enhanced as part of QuickTime 2.5 to better support PowerPC-native components.

On Mac OS computers, the Component Manager dispatcher for calling components is now fat, avoiding the overhead of the mixed mode switches through the old 68K Component Manager dispatch for native-native component calls. DelegateComponentCall is also fat, so native-native delegations avoid the mixed mode switch.

In addition, writing the component dispatch routine for native components has been made significantly easier with the addition of CallComponentFunctionWithStorageProcInfo . This call is analogous to CallComponentFunctionWithStorage , with the addition of a parameter to pass the procedure information for the desired function. This allows the Mixed Mode Manager to correctly dispatch the call without your code having to unravel the parameters from the ComponentParameters block yourself.

To use the new CallComponentFunctionWithStorageProcInfo call, your component needs to link with ComponentsInterfacesLib .

An example component that uses this technique follows. The component supports the required suite of Open, Close, CanDo, and Version calls, as well as a Beep call (selector 0). The ExampleComponentDispatch and ExampleFindRoutineProcPtr routines provide the dispatching using the new CallComponentFunctionWithStorageProcInfo call.

#include <Sound.h>
#include <Components.h>
pascal ComponentResult ExampleComponentDispatch
        (ComponentParameters *params, Handle storage);
static ProcPtr ExampleFindRoutineProcPtr
        (short selector, ProcInfoType *procInfo);
pascal ComponentResult
        ExampleCanDo(Handle storage, short selector);
pascal ComponentResult
        ExampleOpen(Handle storage, ComponentInstance self);
pascal ComponentResult
        ExampleClose(Handle storage,ComponentInstance self);
pascal ComponentResult
        ExampleVersion(Handle storage);
pascal ComponentResult
        ExampleBeep(Handle storage);
#ifdef GENERATINGPOWERPC
struct RoutineDescriptor ExampleComponentDispatchRD =
        BUILD_ROUTINE_DESCRIPTOR(
            (kPascalStackBased | RESULT_SIZE (kFourByteCode) |
                STACK_ROUTINE_PARAMETER (1, kFourByteCode) |
                STACK_ROUTINE_PARAMETER (2, kFourByteCode)),
            ExampleComponentDispatch);
#endif
enum {
    kExampleBeepSelect = 0
};
enum {
    uppExampleBeepProcInfo = kPascalStackBased
         | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
};
pascal ComponentResult
ExampleComponentDispatch(ComponentParameters *params, Handle storage)
{
    ProcPtr theProc;
    ProcInfoType theProcInfo;
    ComponentResult result = codecUnimpErr;
    theProc = ExampleFindRoutineProcPtr(params->what, &theProcInfo);
    if (theProc)
        result = CallComponentFunctionWithStorageProcInfo(
                (Handle)storage, params, theProc, theProcInfo);
    return result;
}
static ProcPtr
ExampleFindRoutineProcPtr(short selector, ProcInfoType *procInfo)
{
    ProcPtr aProc;
    ProcInfoType pi;
#define ComponentCall(a)\
        case kComponent##a##Select: \
            aProc = (ProcPtr)Example##a; \
            pi = uppCallComponent##a##ProcInfo; break;
#define ExampleCall(a)\
        case kExample##a##Select: \
            aProc = (ProcPtr)Example##a; \
            pi = uppExample##a##ProcInfo; break;
    switch (selector) {
        ComponentCall(Version)
        ComponentCall(CanDo)
        ComponentCall(Close)
        ComponentCall(Open)
        ExampleCall(Beep)
        default:
            aProc = nil;
            pi = 0;
        }
    *procInfo = pi;
    return aProc;
}
pascal ComponentResult ExampleCanDo(Handle storage, short selector)
{   
    ProcInfoType ignoreResult;
    return (ExampleFindRoutineProcPtr(selector,&ignoreResult) != 0);
}
pascal ComponentResult ExampleOpen(Handle storage,
    ComponentInstance self)
{
    return noErr;
}
pascal ComponentResult ExampleClose(Handle storage,
    ComponentInstance self)
{
    return(noErr);
}
pascal ComponentResult ExampleVersion(Handle storage)
{
    return 0x00010001;
}
pascal ComponentResult ExampleBeep(Handle storage)
{
    SysBeep(2);
    return noErr;
}

© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next